home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / plnk081.zip / pilot-link.0.8.1 / libsock / memo.c < prev    next >
C/C++ Source or Header  |  1997-08-07  |  2KB  |  84 lines

  1. /* memo.c:  Translate Pilot memopad data formats
  2.  *
  3.  * Copyright (c) 1996, Kenneth Albanowski
  4.  *
  5.  * This is free software, licensed under the GNU Public License V2.
  6.  * See the file COPYING for details.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "pi-source.h"
  13. #include "pi-socket.h"
  14. #include "pi-dlp.h"
  15. #include "pi-memo.h"
  16.  
  17. void free_Memo(struct Memo * a) {
  18.   if(a->text)
  19.     free(a->text);
  20. }
  21.  
  22. int unpack_Memo(struct Memo * a, unsigned char * buffer, int len) {
  23.   if (len<1)
  24.     return 0;
  25.   a->text = strdup((char*)buffer);
  26.   return strlen((char*)buffer)+1;
  27. }
  28.  
  29. int pack_Memo(struct Memo * a, unsigned char * buffer, int len) {
  30.   int destlen = (a->text ? strlen(a->text) : 0)+1;
  31.   if (!buffer)
  32.     return destlen;
  33.   if (len < destlen)
  34.     return 0;
  35.   if(a->text) {
  36.     if (buffer)
  37.       strcpy((char*)buffer,a->text);
  38.     return strlen(a->text)+1;
  39.   } else {
  40.     if (buffer)
  41.       buffer[0] = 0;
  42.     return 1;
  43.   }
  44. }
  45.                   
  46. int unpack_MemoAppInfo(struct MemoAppInfo * ai, unsigned char * record, int len) {
  47.   unsigned char * start = record;
  48.   int i = unpack_CategoryAppInfo(&ai->category, record, len);
  49.   if (!i)
  50.     return i;
  51.   record += i;
  52.   len -= i;
  53.   if (len >= 4) {
  54.     record += 2;
  55.     ai->sortByAlpha = get_byte(record);
  56.     record += 2;
  57.   } else {
  58.     ai->sortByAlpha = 0;
  59.   }
  60.   return (record-start);
  61. }
  62.  
  63. int pack_MemoAppInfo(struct MemoAppInfo * ai, unsigned char * record, int len) {
  64.   int i;
  65.   unsigned char * start = record;
  66.   i=pack_CategoryAppInfo(&ai->category, record, len);
  67.   if (!record)
  68.     return i + 4;
  69.   if (i==0) /* category pack failed*/
  70.     return 0;
  71.   record += i;
  72.   len -= i;
  73.   if (len<4)
  74.     return (record-start);
  75.   set_short(record, 0); /* gapfil new for 2.0 */
  76.   record += 2;
  77.   set_byte(record, ai->sortByAlpha); /* new for 2.0 */
  78.   record++;
  79.   set_byte(record, 0); /* gapfil new for 2.0 */
  80.   record++;
  81.   
  82.   return (record-start);
  83. }
  84.